import { Controller, Get, Post, Body, Inject, Query, Req } from '@nestjs/common';
import { StarService } from './star.service';
import { RequireLogin, UserInfo } from 'src/custom.decorator';
import { BlogService } from 'src/blog/blog.service';
import { CommentService } from 'src/comment/comment.service';
import { Request } from 'express';

@Controller('star')
export class StarController {
  constructor(private readonly starService: StarService) {}
  
  // 收藏
  @RequireLogin()
  @Post('add')
  async star(@Body('createId') createId: number, @UserInfo('userId') userId: number, @Body('type') type: number, @Body('authorId') authorId: number, @Req() req: Request) {
    await this.starService.create({
      createId: createId,
      userId: userId,
      type: type,
      authorId: authorId,
      ip: req.ip
    })
  }

  // 取消收藏
  @RequireLogin()
  @Post('del')
  async unStar(@Body('createId') createId: number, @Body('id') id: number, @UserInfo('userId') userId: number, @Body('type') type: number) {
    await this.starService.remove({id, createId, type, userId});
  }

  @RequireLogin()
  @Post('findByCreateIdAndType')
  async findByCreateIdAndType(@Body('createId') createId: number, @Body('type') type: number, @Body('userId') userId: number) {
    return await this.starService.findByCreateIdAndType({createId, type, userId})
  }

  @RequireLogin()
  @Post('queryStarTotal')
  async queryStarTotal(@UserInfo('userId') userId: number) {
    return await this.starService.queryStarTotal(userId)
  }
}
